package geos;

import com.sun.corba.se.impl.orb.ParserTable;
import java.beans.PropertyVetoException;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;

//@autora Suellen
// Tela principal do GeOS
public class FrmTelaInicial extends javax.swing.JFrame {

    private final int FRM_ORCAMENTO = 1;
    private final int FRM_CLIENTE = 2; 

    /**
     * Verifica se o InternalFrame já está aberto e o move para a frente
     *
     * @param c o código pra saber qual tela<br>
     * 1 - FrmOrcamento<br>
     * 2 = FrmCliente
     * @return boolean true ou false se encontrou ou não a instância do frame
     */
    public boolean verificainstancia(int c) throws PropertyVetoException {
        JInternalFrame[] results;
        results = this.principalDesktopPane.getAllFrames();
        for (JInternalFrame result : results) {
            //System.out.println(result.getClass());
            switch (c) {
                case 1:
                    if (result instanceof FrmOrcamento) {
                        result.moveToFront();
                        result.setMaximum(true);
                        return true;
                    }
                    break;
                case 2:
                    if (result instanceof FrmCliente) {
                        result.moveToFront();
                        result.setMaximum(true);
                        return true;
                    }
                    break;
            }
        }
        return false;
    }
    private static FrmTelaInicial TelaInicial;

    public static FrmTelaInicial getInstancia() {
        if (TelaInicial == null) {
            TelaInicial = new FrmTelaInicial();
        }
        return TelaInicial;
    }

    //Metodo Construtor:
    public FrmTelaInicial() {
        initComponents();
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        principalDesktopPane = new javax.swing.JDesktopPane();
        ferramentaBar = new javax.swing.JToolBar();
        clienteButton = new javax.swing.JButton();
        orcamentoButton = new javax.swing.JButton();
        sairButton = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        principalMenul = new javax.swing.JMenu();
        clienteMenuItem = new javax.swing.JMenuItem();
        orcamentoMenuItem = new javax.swing.JMenuItem();
        sairMenuItem = new javax.swing.JMenuItem();
        cadastroMenu = new javax.swing.JMenu();
        servicoMenuItem = new javax.swing.JMenuItem();
        produtoMenuItem = new javax.swing.JMenuItem();
        pagamentoMenuItem = new javax.swing.JMenuItem();
        statusMenuItem = new javax.swing.JMenuItem();
        ajudaMenu = new javax.swing.JMenu();
        sobreMenuItem = new javax.swing.JMenuItem();

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("GeOS");
        setExtendedState(6);

        principalDesktopPane.setBackground(new java.awt.Color(204, 204, 204));
        principalDesktopPane.setAutoscrolls(true);

        ferramentaBar.setFloatable(false);
        ferramentaBar.setRollover(true);

        clienteButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GEOS/icones/32x32/users-icon (Custom).png"))); // NOI18N
        clienteButton.setFocusable(false);
        clienteButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        clienteButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        clienteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clienteButtonActionPerformed(evt);
            }
        });
        ferramentaBar.add(clienteButton);

        orcamentoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GEOS/icones/32x32/Money_Calculator_48 (Custom).png"))); // NOI18N
        orcamentoButton.setFocusable(false);
        orcamentoButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        orcamentoButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        orcamentoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                orcamentoButtonActionPerformed(evt);
            }
        });
        ferramentaBar.add(orcamentoButton);

        sairButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GEOS/icones/32x32/Log-Out-icon (Custom).png"))); // NOI18N
        sairButton.setFocusable(false);
        sairButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        sairButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        sairButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sairButtonActionPerformed(evt);
            }
        });
        ferramentaBar.add(sairButton);

        menuBar.setMinimumSize(new java.awt.Dimension(0, 5));

        principalMenul.setMnemonic('f');
        principalMenul.setText("Principal");
        principalMenul.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N

        clienteMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        clienteMenuItem.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        clienteMenuItem.setMnemonic('o');
        clienteMenuItem.setText("Cliente");
        clienteMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clienteMenuItemActionPerformed(evt);
            }
        });
        principalMenul.add(clienteMenuItem);

        orcamentoMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        orcamentoMenuItem.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        orcamentoMenuItem.setMnemonic('s');
        orcamentoMenuItem.setText("Orçamento");
        orcamentoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                orcamentoMenuItemActionPerformed(evt);
            }
        });
        principalMenul.add(orcamentoMenuItem);

        sairMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        sairMenuItem.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        sairMenuItem.setMnemonic('x');
        sairMenuItem.setText("Sair");
        sairMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sairMenuItemActionPerformed(evt);
            }
        });
        principalMenul.add(sairMenuItem);

        menuBar.add(principalMenul);

        cadastroMenu.setMnemonic('e');
        cadastroMenu.setText("Cadastro");
        cadastroMenu.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N

        servicoMenuItem.setBackground(new java.awt.Color(0, 0, 0));
        servicoMenuItem.setMnemonic('t');
        servicoMenuItem.setText("Serviço");
        servicoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                servicoMenuItemActionPerformed(evt);
            }
        });
        cadastroMenu.add(servicoMenuItem);

        produtoMenuItem.setMnemonic('y');
        produtoMenuItem.setText("Produto");
        produtoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                produtoMenuItemActionPerformed(evt);
            }
        });
        cadastroMenu.add(produtoMenuItem);

        pagamentoMenuItem.setText("Forma Pagamento");
        pagamentoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pagamentoMenuItemActionPerformed(evt);
            }
        });
        cadastroMenu.add(pagamentoMenuItem);

        statusMenuItem.setText("Status Orçamento");
        statusMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                statusMenuItemActionPerformed(evt);
            }
        });
        cadastroMenu.add(statusMenuItem);

        menuBar.add(cadastroMenu);

        ajudaMenu.setMnemonic('h');
        ajudaMenu.setText("Ajuda");
        ajudaMenu.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N

        sobreMenuItem.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        sobreMenuItem.setMnemonic('a');
        sobreMenuItem.setText("Sobre");
        sobreMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sobreMenuItemActionPerformed(evt);
            }
        });
        ajudaMenu.add(sobreMenuItem);

        menuBar.add(ajudaMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(principalDesktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE)
            .addComponent(ferramentaBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(ferramentaBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(principalDesktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE))
        );

        getAccessibleContext().setAccessibleDescription("");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void sairMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sairMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_sairMenuItemActionPerformed

    private void orcamentoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orcamentoMenuItemActionPerformed
        try {
            if (!verificainstancia(FRM_ORCAMENTO)) {
                FrmOrcamento form = new FrmOrcamento();
                principalDesktopPane.add(form);
                form.setVisible(true);
                form.setMaximum(true);
                form.setSelected(true);
            }

        } catch (java.beans.PropertyVetoException e) {
        }

    }//GEN-LAST:event_orcamentoMenuItemActionPerformed

    private void clienteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clienteMenuItemActionPerformed
        try {
            if (!verificainstancia(FRM_CLIENTE)) {
                FrmCliente form = new FrmCliente();
                principalDesktopPane.add(form);
                form.setVisible(true);
                form.setMaximum(true);
                form.setSelected(true);
            }
        } catch (java.beans.PropertyVetoException e) {

        }                                       // TODO add your handling code here:
    }//GEN-LAST:event_clienteMenuItemActionPerformed

    private void sairButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sairButtonActionPerformed
        System.exit(0);
    }//GEN-LAST:event_sairButtonActionPerformed

    private void orcamentoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orcamentoButtonActionPerformed
        try {
            if (!verificainstancia(FRM_ORCAMENTO)) {
                FrmOrcamento form = new FrmOrcamento();
                principalDesktopPane.add(form);
                form.setVisible(true);
                form.setMaximum(true);
                form.setSelected(true);
            }

        } catch (java.beans.PropertyVetoException e) {
        }
    }//GEN-LAST:event_orcamentoButtonActionPerformed

    private void clienteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clienteButtonActionPerformed
        try {
            if (!verificainstancia(FRM_CLIENTE)) {
                FrmCliente form = new FrmCliente();
                principalDesktopPane.add(form);
                form.setVisible(true);
                form.setMaximum(true);
                form.setSelected(true);
            }
        } catch (java.beans.PropertyVetoException e) {

        }

    }//GEN-LAST:event_clienteButtonActionPerformed

    private void servicoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_servicoMenuItemActionPerformed

        new GEOS.FrmServico().setVisible(true);
    }//GEN-LAST:event_servicoMenuItemActionPerformed

    private void sobreMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sobreMenuItemActionPerformed

    }//GEN-LAST:event_sobreMenuItemActionPerformed

    private void produtoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_produtoMenuItemActionPerformed

        new GEOS.FrmProduto().setVisible(true);
    }//GEN-LAST:event_produtoMenuItemActionPerformed

    private void pagamentoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pagamentoMenuItemActionPerformed

        new GEOS.FrmFormaPagamento().setVisible(true);
    }//GEN-LAST:event_pagamentoMenuItemActionPerformed

    private void statusMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_statusMenuItemActionPerformed

        new GEOS.FrmStatusOrcamento().setVisible(true);
    }//GEN-LAST:event_statusMenuItemActionPerformed

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmTelaInicial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmTelaInicial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmTelaInicial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmTelaInicial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrmTelaInicial().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu ajudaMenu;
    private javax.swing.JMenu cadastroMenu;
    private javax.swing.JButton clienteButton;
    private javax.swing.JMenuItem clienteMenuItem;
    private javax.swing.JToolBar ferramentaBar;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JButton orcamentoButton;
    private javax.swing.JMenuItem orcamentoMenuItem;
    private javax.swing.JMenuItem pagamentoMenuItem;
    private javax.swing.JDesktopPane principalDesktopPane;
    private javax.swing.JMenu principalMenul;
    private javax.swing.JMenuItem produtoMenuItem;
    private javax.swing.JButton sairButton;
    private javax.swing.JMenuItem sairMenuItem;
    private javax.swing.JMenuItem servicoMenuItem;
    private javax.swing.JMenuItem sobreMenuItem;
    private javax.swing.JMenuItem statusMenuItem;
    // End of variables declaration//GEN-END:variables

}
